package com.example.qq_demo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;

public class Login_Activity extends AppCompatActivity {
        private Button register;
        private Button logIn;
        private EditText uname,upwd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_);
        initView();
    }

    public void initView(){
        register=findViewById(R.id.register);
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Login_Activity.this,Register_Activity.class);
                startActivity(intent);
            }
        });
        logIn=findViewById(R.id.go);
        logIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Login_Activity.this,Index_Activity.class);
                startActivity(intent);
            }
        });

        uname=findViewById(R.id.user);
        upwd=findViewById(R.id.upwd);
        String data;
        BufferedReader dr=null;
        FileInputStream fis=null;
        try {
            fis=openFileInput("text.txt");
            dr=new BufferedReader(new InputStreamReader(fis));
            data=dr.readLine();
            String str=new String(data);
            String[] data1=str.split(":");
            uname.setText(data1[0]);
            upwd.setText(data1[1]);
            dr.close();
            fis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
